package com.study.example.study.extension.easyexcel.write;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * easyexcel 写数据提供枚举类
 *
 * @author RenYuLiang
 */
@Getter
public enum EasyExcelWriteStrategyEnum {


    /**
     * 测试
     */
    TEST("test", "test", new String[]{"test1",
            "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9", "test10"},
            new String[]{"testEasyExcelWriteDataHandlerStrategy", "testEasyExcelWriteDataHandlerStrategy",
                    "testEasyExcelWriteDataHandlerStrategy", "testEasyExcelWriteDataHandlerStrategy",
                    "testEasyExcelWriteDataHandlerStrategy", "testEasyExcelWriteDataHandlerStrategy",
                    "testEasyExcelWriteDataHandlerStrategy", "testEasyExcelWriteDataHandlerStrategy",
                    "testEasyExcelWriteDataHandlerStrategy", "testEasyExcelWriteDataHandlerStrategy"});

    /**
     * 写数据类型
     */
    private final String type;
    /**
     * 文件名
     */
    private final String fileName;
    /**
     * excel sheet 名称
     */
    private final String[] sheetArray;
    /**
     * excel 数据处理类 顺序和数量 须和 sheetArray 保持一致
     */
    private final String[] writeHandlerArray;

    EasyExcelWriteStrategyEnum(String type, String fileName, String[] sheetArray, String[] writeHandlerArray) {
        this.type = type;
        this.fileName = fileName;
        this.sheetArray = sheetArray;
        this.writeHandlerArray = writeHandlerArray;
    }

    /**
     * 根据 name 获取 EasyExcelWriteStrategyEnum
     *
     * @param name 类似 TEST
     * @return EasyExcelWriteStrategyEnum
     */
    public static EasyExcelWriteStrategyEnum getByName(final String name) {
        return EasyExcelWriteStrategyEnum.valueOf(name);
    }

    /**
     * 根据 type 获取 EasyExcelWriteStrategyEnum
     *
     * @param type String
     * @return EasyExcelWriteStrategyEnum
     */
    public static EasyExcelWriteStrategyEnum getByType(final String type) {
        return Arrays.stream(EasyExcelWriteStrategyEnum.values()).filter(e -> Objects.equals(type, e.type)).findFirst().orElse(null);
    }

    public String getType() {
        return type;
    }

    public String getFileName() {
        return fileName;
    }

    public String[] getSheetArray() {
        return sheetArray;
    }

    public String[] getWriteHandlerArray() {
        return writeHandlerArray;
    }

}
